package com.controller.secretary;

import java.util.Date;
import java.util.List;

import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.model.Thesissource;

public class thesissourceController extends Controller {
	@ActionKey("/thesissource-save")
	public void save(){
		//根据教学秘书所在的系和课题名称找来源的主键，若为空就新增，否则就是修改
		Thesissource ts=getModel(Thesissource.class,"t");
		Date d=new Date();
		ts.set("thesissource_department",1).set("thesissource_addtime",d);
		ts.save();
		renderJson("{\"success\":true}");
	}
	@ActionKey("/thesissource-updated")
	public void update(){
		Thesissource ts=getModel(Thesissource.class,"t");
		ts.update();
		renderJson("{\"success\":true}");
	}
	@ActionKey("/thesissource-del")
	public void del(){
		Thesissource ts=getModel(Thesissource.class,"t");
		ts.delete();
		renderJson("{\"success\":true}");
	}

	@ActionKey("/thesissource-show")
	public void show(){
		System.out.println("教学秘书课题来源");
		//int s_id=getSessionAttr("secretary_id");//通过教学秘书的主键找到他所在的系
		int s_id=209;
		String f="select teacher_department from teacher where teacher_id="+s_id+"";
		int d_p=Db.queryInt(f);//找到教师所在的系
		String sql="select secretary_7.* from secretary_7 where thesissource_department="+d_p+" and teacher_id="+s_id+"";
		List<Record> list=Db.find(sql);
		System.out.println(list);
		setSessionAttr("se", list);
		renderJson(list);
	}
	
}
